package com.situ.mall.controller.front;

import java.util.List;

import com.situ.mall.pojo.entity.Category;
import com.situ.mall.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.situ.mall.pojo.entity.Product;
import com.situ.mall.service.IProductService;


@Controller
@RequestMapping("/frontList")
public class FrontListController {
	@Autowired
	private IProductService productService;
	@Autowired
	private ICategoryService categoryService;

	// 转到商品列表页面
	@RequestMapping("/getListPage.shtml")
	public String getListPage(Integer categoryId, Model model) {
		List<Product> list = productService.selectByCategoryId(categoryId);
		for (Product product : list) {
			System.out.println(product);
		}
		List<Category> topCategoryList = categoryService.selectTopCategory();
		List<Category> secondCategoryList = categoryService.selectSecondCategoryList();
		model.addAttribute("topCategoryList", topCategoryList);
		model.addAttribute("secondCategoryList", secondCategoryList);
		model.addAttribute("productList", list);
		return "/front/search-goods";
	}

}
